#include "stdafx.h"

#include "readBaumerMex.h"

/// Restart the cameras.
/// Stops both cameras, resets the frame counters, then starts the cameras again. Slave camera is
/// startet first, master camera approximately 50 ms later to make sure slave camera is ready 
/// when triggert by master camera.
///
/// It can take up to about 50 ms until the callback function is executed the first time after
/// calling this function. Therefore it is recommended to wait 50 ms before proceeding after
/// calling this function.
int restart() {
	if (isInitialised) {
		mexPrintf("Stopping cameras.\n");
		res = camera[camindex[CAM_MASTER]].pCamera->setStart( false );
		res = camera[camindex[CAM_SLAVE]].pCamera->setStart( false );

		mexPrintf("Resetting frame counters.\n");
		res = camera[0].pCamera->setFrameCounter( 0, 0 );
		res = camera[1].pCamera->setFrameCounter( 0, 0 );

		mexPrintf("Starting cameras.\n");
		res = camera[camindex[CAM_SLAVE]].pCamera->setStart( true );
		Sleep(50);
		res = camera[camindex[CAM_MASTER]].pCamera->setStart( true );
	} else {
		mexPrintf("Restart: System is not initialised. Restarting cameras not possible.\n");
	}

	return 0;
}